<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    template="/WEB-INF/templates/baseLayout.xhtml">

	<ui:define name="title">
		<h:outputText value="DAMATE - #{msg['TabPanel.resources']}" />
	</ui:define>

    <ui:define name="resources">
        <p:panel styleClass="imgHeader resourcesPage" toggleable="true" widgetVar="resourcesPanel">
            <f:facet name="header">
                <h:graphicImage library="images" name="tree-16.png" />
                <h:outputText styleClass="title" value="#{msg['resourcesPage.resourceBrowser.title']}" />
            </f:facet>
            <h:panelGrid columns="2" columnClasses="treeCol,selectorCol">
                <h:panelGroup>
                    <h:outputText value="#{msg['resourcesPage.resourceBrowser.tree.title']}" styleClass="treeTitle" />
                    <ui:include src="/WEB-INF/resources/observedEntityTree.xhtml" />
                </h:panelGroup>
                <h:panelGroup>
                    <h:panelGrid columns="3" styleClass="selectors" columnClasses="icon,label,input">
                        <h:graphicImage library="images" name="user.png" />
                        <h:outputText value="#{msg['resourcesPage.resourceBrowser.user']}" />
                        <p:selectOneMenu value="#{resourcesView.user}" panelStyleClass="selectUserPanel"
                                         filter="true" filterMatchMode="contains" converter="#{resourcesView.userConverter}">
                            <f:selectItem itemLabel="#{msg['resourcesPage.resourceBrowser.user.filter.selectUser']}" itemValue="" />
                            <f:selectItems value="#{resourcesView.activeUsers}" var="user" itemLabel="#{user.firstname} #{user.lastname} (#{user.username})" itemValue="#{user.username}"/>
                            <p:ajax process="@this" update="idIPAddress idWorkspace resourceTree resourceActions" />
                        </p:selectOneMenu>
                        <h:graphicImage library="images" name="computer-16.png" />
                        <h:outputText value="#{msg['resourcesPage.resourceBrowser.ipAddress']}" />
                        <p:selectOneMenu id="idIPAddress" value="#{resourcesView.ipAddress}" disabled="#{resourcesView.user == null}">
                            <f:selectItem itemLabel="#{msg['resourcesPage.resourceBrowser.user.filter.selectIP']}" itemValue="" />
                            <f:selectItems value="#{resourcesView.availableIPAddresses}" var="ip" itemLabel="#{ip}" itemValue="#{ip}"/>
                            <p:ajax process="@this" update="idWorkspace resourceTree resourceActions" />
                        </p:selectOneMenu>
                        <h:graphicImage library="images" name="database-16.png" />
                        <h:outputText value="#{msg['resourcesPage.resourceBrowser.workspace']}" />
                        <p:selectOneMenu id="idWorkspace" value="#{resourcesView.workspace}" disabled="#{resourcesView.ipAddress == null}" converter="#{resourcesView.workspaceConverter}" style="width: 278px;">
                            <f:selectItem itemLabel="#{msg['resourcesPage.resourceBrowser.user.filter.selectWorkspace']}" itemValue="" />
                            <f:selectItems value="#{resourcesView.availableWorkspaces}" var="workspace" itemLabel="#{workspace.path}" itemValue="#{workspace}"/>
                            <p:ajax process="@this" update="resourceTree resourceActions idWorkspacePath" />
                        </p:selectOneMenu>
                        <h:outputText /><h:outputText />
                        <h:panelGroup id="idWorkspacePath" style="font-size: 11px">
                            <h:outputText value="#{msg['resourcesPage.resourceBrowser.workspace.fullPath']}: " style="font-weight: bold" rendered="#{resourcesView.workspace != null}" />
                            <h:outputText value="#{resourcesView.workspace.path}" rendered="#{resourcesView.workspace != null}" />
                        </h:panelGroup>
                    </h:panelGrid>
                    <h:panelGroup id="resourceActions" layout="block" styleClass="resourceActions">
                        <h:panelGrid columns="3" rendered="#{resourcesView.selectedNode != null and resourcesView.selectedNode.type != 'empty'}" columnClasses="label,input,button">
                            <h:outputText value="#{msg['resourcesPage.resourceBrowser.assignTask']}:" />
                            <p:selectOneMenu id="idTask" value="#{resourcesView.selectedTaskToAssign}" converter="#{resourcesView.taskConverter}">
                                <f:selectItem itemLabel="#{msg['resourcesPage.resourceBrowser.assignTask.noSelected']}" itemValue="" />
                                <f:selectItems value="#{resourcesView.availableTasks}" var="task" itemLabel="#{task.name}" itemValue="#{task}" />
                            </p:selectOneMenu>
                            <p:commandButton value="#{msg['Common.save']}" icon="save" process="@this idTask" action="#{resourcesView.assignTask}" />
                            <h:outputText value="#{msg['resourcesPage.resourceBrowser.events']}:" />
                            <p:commandButton value="#{msg['Common.show']}" icon="show" process="@this" action="#{resourcesView.showEvents}"
                                             update="selectedResourceEvents" oncomplete="resourcesPanel.toggle();eventsPanel.getJQ().show();" />
                        </h:panelGrid>
                    </h:panelGroup>
                </h:panelGroup>
            </h:panelGrid>
        </p:panel>
        <p:panel id="selectedResourceEvents" styleClass="imgHeader eventsPanel" style="display: none" widgetVar="eventsPanel">
            <f:facet name="header">
                <h:graphicImage library="images" name="event-list-16.png" />
                <h:outputText styleClass="title" value="#{msg['resourcesPage.resourceBrowser.events']}" />
            </f:facet>
            <p:dataTable value="#{resourcesView.selectedResourceEvents}" var="event" rendered="#{resourcesView.selectedResourceEvents != null}">
                <p:column headerText="#{msg['resourcesPage.resourceBrowser.events.tableTitle.project']}">
                    <h:outputText value="#{event.relatedObject.project.name}" />
                </p:column>
                <p:column headerText="#{msg['resourcesPage.resourceBrowser.events.tableTitle.resource']}">
                    <h:outputText value="#{event.relatedObject.path}" />
                </p:column>
                <p:column headerText="#{msg['resourcesPage.resourceBrowser.events.tableTitle.type']}">
                    <h:outputText value="#{event.eventType.name}" />
                </p:column>
                <p:column headerText="#{msg['resourcesPage.resourceBrowser.events.tableTitle.date']}">
                    <h:outputText value="#{event.date}" />
                </p:column>
                <p:column headerText="#{msg['resourcesPage.resourceBrowser.events.tableTitle.parameters']}">
                    <h:outputText value="no parameters..." rendered="#{event.parameters == null or event.parameters.isEmpty()}" />
                    <ui:repeat value="#{event.parameters}" var="param">
                        <h:outputText value="#{param.paramName} = #{param.paramValue}" />
                    </ui:repeat>
                </p:column>
            </p:dataTable>

            <p:commandButton style="margin-top: 10px" value="#{msg['Common.back']}" icon="back" onclick="resourcesPanel.toggle();eventsPanel.getJQ().hide();" />
        </p:panel>
	</ui:define>

    <ui:define name="onAfterPageLoad">
        <script type="text/javascript" language="JavaScript">
            $(document).ready(function (){
                selectTab("resources");
            });
        </script>
    </ui:define>
</ui:composition>
